//
//  HEOrderGoodsOperationCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/6.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEOrderGoodsOperationCell.h"

@interface HEOrderGoodsOperationCell ()

@property (nonatomic, strong) NSMutableArray *ButtonArray;
@property (nonatomic, strong) NSMutableArray *itemsArr;
@property (nonatomic, strong) NSArray *btnModels;
@property (nonatomic, strong) QMUIGhostButton *checkBtn;

@end

@implementation HEOrderGoodsOperationCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         self.selectionStyle = UITableViewCellSelectionStyleNone;
         [self initUI];
     }
     return self;;
}


-(void)initUI {
   
    QMUIGhostButton *checkBtn = [[QMUIGhostButton alloc] initWithGhostColor:CNavBgColor];
    _checkBtn = checkBtn;
    checkBtn.titleLabel.font = DYBlodFont(14);
        [checkBtn setTitle:@"取消售后" forState:UIControlStateNormal];
    [checkBtn setTitleColor:CNavLightBlackColor forState:UIControlStateNormal];
    checkBtn.ghostColor = CNavLightBlackColor;
        [checkBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:checkBtn];

    [checkBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.width.mas_offset(80).priorityLow();
        make.height.mas_offset(30);
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
}

 

- (void)btnClick:(QMUIGhostButton *)btn {
    NSInteger tag = btn.tag;
    NSDictionary *dict = self.btnModels[tag];
    NSNumber *type = dict[@"type"];
    
    if ([_delegate respondsToSelector:@selector(orderGoodsOperationCell:orderItem:type:)]) {
        [_delegate orderGoodsOperationCell:self orderItem:_model type:type.integerValue];
    }
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    
    self.delegate = formModel.proxyVC;
    HEOrderItemModel *model = self.formModel.od_itemList[indexPath.row];
    _model = model;
    
 
    if (_model.afterOperationStatus == HEOrderGoodsOperationTypeApplySales) {
        _btnModels = @[@{@"name":@"申请售后", @"color":CNavLightBlackColor, @"type": [NSNumber numberWithInteger:HEOrderGoodsOperationTypeApplySales]}];
    }else if (_model.afterOperationStatus == HEOrderGoodsOperationTypeCancelApply) {
        _btnModels = @[@{@"name":@"取消售后", @"color":CNavBgColor, @"type": [NSNumber numberWithInteger:HEOrderGoodsOperationTypeCancelApply]}];
    }else if (_model.refundStatus == HEOrderRefuseStatusWaitSellerReture) {
        _btnModels = @[@{@"name":@"填写退货信息", @"color":CPriceColor, @"type": [NSNumber numberWithInteger:HEOrderGoodsOperationTypeFill]}];
    }
    
    if (_btnModels.count > 0) {
        NSDictionary *dict = self.btnModels[0];
        [_checkBtn setTitle:dict[@"name"] forState:UIControlStateNormal];
        [_checkBtn setTitleColor:dict[@"color"] forState:UIControlStateNormal];
        _checkBtn.ghostColor = dict[@"color"];
        [_checkBtn addTarget:self action:@selector(btnClick:)
            forControlEvents:UIControlEventTouchUpInside];
        
        [_checkBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset([dict[@"name"] widthForFont:DYFont(14)] + 20).priorityMedium();
        }];
    }
}

#pragma mark - Getter

- (NSMutableArray *)ButtonArray {
    if(!_ButtonArray){
        _ButtonArray = [[NSMutableArray alloc] init];
    }
    return _ButtonArray;
}


@end


